package com.thinkgem.jeesite.common.filter;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.springframework.stereotype.Component;

import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

@Component
public class MyLogoutFilter extends LogoutFilter {

	@Override
	protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
		String userId = UserUtils.getUser().getId();
		@SuppressWarnings("unchecked")
		Map<String, String> ipMap = (Map<String, String>) CacheUtils.get("IpMap",new HashMap<>());
		if (ipMap.containsKey(userId)) {
			ipMap.remove(userId);
		}
		return super.preHandle(request, response);
	}
	
}
